const app = getApp();
const db = wx.cloud.database();
var barrage_style_arr = [];
var barrage_style_obj = {};
var phoneWidth = 0;
var timers = [];
var timer;
Page({
  data: {
    shopping_list: {},
    user_list: {},
    userInfo: {},
    comment_list: {},
    shopName: '',
    shopPhoto: '',
    id: '',
    remove: false,
    qq:"",
    wechart:"",
    openId: '',
    comment: '',
    comment_id: '',
    myShoppingCount: ''
  },
  tishi(){
    wx.showModal({
      content: '谨记，一切交易必须线下见面交易，防止被欺骗。开学季网络诈骗较多，一定要注意资金安全。',
      showCancel: true,
      title: '温馨提示',
    })
  },
  onLoad: function (options) {
    console.log(options)
    wx.hideShareMenu();
    var that = this;
    var id = options.id;
    var that = this;
    that.data.comment_id = id;
    that.data.id = id;
    //获取用户信息
    wx.showLoading({
      title: '加载中...',
    })

    db.collection('secondHand').doc(id).get({
      success: function (res) {
        console.log(res)
        that.setData({
          shopping_list: res.data,
          qq:res.data.qq,
          wechart:res.data.wechart
        })
        wx.hideLoading({
          success: (res) => {},
        })
      },
    })
  },

  copyQQ(){
    var that = this ;
    wx.setClipboardData({
      data: that.data.qq,
      success: function (res) {
        wx.getClipboardData({
          success: function (res) {
            wx.showToast({
              title: '复制成功'
            })
          }
        })
      }
    })
  },
  copyWechart(){
    var that = this ;
    wx.setClipboardData({
      data: that.data.wechart,
      success: function (res) {
        wx.getClipboardData({
          success: function (res) {
            wx.showToast({
              title: '复制成功'
            })
          }
        })
      }
    })
  },
  // 预览图片
  previewImg: function (e) {
    var that = this;
    wx.showLoading({
      title: '加载中...',
    })
    var img = that.data.shopping_list.fileList;
    var current = e.target.dataset.src;
    // 给图片逐个命名
    var imgArr = [];
    var objkeys = Object.keys(img);
    for (let i = 0; i < objkeys.length; i++) {
      imgArr.push(that.data.shopping_list.fileList[i]);
    }
    wx.previewImage({
      current: current,
      urls: imgArr,
    })
    setTimeout(function () {
      wx.hideLoading()
    }, 500)
  },
  kefu: function (e) {
    wx.makePhoneCall({
      phoneNumber: '17339873895',
    })
  }
})